home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15432 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  72 lines

  1. Path: argonet.co.uk!argbd86
  2. From: Charlotte Tomlinson <eeyore@argonet.co.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Linked lists - will this work?
  5. Date: Fri, 05 Apr 1996 15:09:41
  6. Organization: UnipalmPIPEX server (post doesn't reflect views of UnipalmPIPEX
  7. Distribution: world
  8. Message-ID: <internews46BA23486F@argonet.co.uk>
  9. Reply-To: Charlotte Tomlinson <eeyore@argonet.co.uk>
  10. NNTP-Posting-Host: ai161.du.pipex.com
  11. X-Newsreader: VTi Voyager InterNews 0.15 for Acorn RISC OS (Patched by RA)
  12.  
  13. Hi all,
  14.  
  15. I posted a few days ago, and got several varied answers to my list problem
  16. (thanks, everyone).  But I want to check if what I am considering doing
  17. will work and is reasonable sensible.
  18.  
  19. I have implemented a template doubly linked list, the backbones of which
  20. is as follows:
  21.  
  22. template <class T> class node
  23. {
  24.         public:
  25.         T data;
  26.         node<T> *next;
  27.         node<T> *prev;
  28. /*other functions*/
  29. };
  30.  
  31. template <class T> class dllist : public node<T>
  32. {
  33.         node<T> *start, *end;
  34.         void copy(const dllist<T>);
  35.  
  36.         public:
  37. /*fns snipped*/
  38. };
  39.  
  40.  
  41. If I implemented a new member fn for dllist along the lines of:
  42.  
  43. void dllist::iterate(T (*fptr)(T))
  44. {
  45. node<T> *temp;
  46. temp=getstart();
  47. while(temp)
  48.     {
  49.     temp->change(f(temp->getinfo));
  50.     temp=temp->next;
  51.     }
  52. }
  53.  
  54. Would that have the effect I require, of taking a function which takes a T
  55. as its argument and performing that over the list?  If it would do that,
  56. would it be reasonable 'safe' to use it also for functions that do not
  57. actually change the data in their body, but return the value passed after,
  58. say, printing it?
  59.  
  60. Many thanks in advance.
  61.  
  62.  
  63.  
  64. ... Windows?  I saw through them!
  65. -- 
  66. -----------------------------------------------------------------------------
  67. | Charlotte Tomlinson  |    Mediocrity know nothing higher than itself,     |
  68. | eeyore@argonet.co.uk |       but talent instantly recognises genius.      |
  69. |---------------------------------------------------------------------------|
  70. --------- Now WWWebbed up at http://www.argonet.co.uk/users/eeyore/ ---------
  71.  
  72.